#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Filename: get_workflow_info.py
# Author: ChenChangSong
# Date: 2025-08-24
"""
功能描述: 获取需求工作流信息
"""
from comm.common_code import *
# 导入必要的模块
from comm.common_code import get_excel_data, logger, log_to_ui_info, log_to_ui_error

def req_get_workflow_info():
    """
    获取需求或bug的工作流信息
    """
    excel_data = get_excel_data()
    url = f"https://www.tapd.cn/api/entity/workflow/get_workflow_info?workspace_id={excel_data["项目ID"]}&program_id=&entity_type=story&workflow_id=1166606973001000016&entity_id=1166606973001054795"
    payload={}
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Cookie':excel_data['Cookie'],
        'Referer': f'https://www.tapd.cn/tapd_fe/{excel_data["项目ID"]}/story/detail/1166606973001054795',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.97 Safari/537.36 Core/1.116.559.400 QQBrowser/19.6.6683.400',
        'sec-ch-ua': '"Not)A;Brand";v="24", "Chromium";v="116"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"'
    }
    response_code, response = api_request(method="GET", url=url, headers=headers, data=payload)
    # logger.info(f"获取需求或bug的工作流信息 - 响应内容:\n {response}")
    all_steps_dict = {}
    if response_code == 200:

        all_steps = response['data']['all_steps']
        for step_name,step_data in all_steps.items():
            name_original = step_data['NameOriginal'] # 原始名称
            name_alias = step_data['NameAlias']       # 需求状态名
            all_steps_dict[name_original] = name_alias  
        logger.info(f"获取需求或bug的工作流信息 - 所有状态:\n {all_steps_dict}")
    else:
        logger.error(f"获取需求或bug的工作流信息 - 失败")
    return all_steps_dict
if __name__ == '__main__':
    req_get_workflow_info()
